#include <18F452.H>
#device ADC=10
#use delay(clock=4000000)
#fuses HS, NOWDT, NOLVP, NOPROTECT,NOBROWNOUT,PUT

#include <LCD.C>

void main (void)
{
	int16 filtro_temp[8]={0,0,0,0,0,0,0,0},promedio_temp=0;
	int8 i;
	float temperatura;
	setup_adc(ADC_CLOCK_INTERNAL);
 	setup_adc_ports(AN0);//declaracion pines analogicos
	set_adc_channel(0);
	delay_us(20);
	lcd_init(); //inicializa lcd
	lcd_gotoxy(3,1);
	lcd_putc("\fTEMPERATURA");
	while(1)
	{
		for (i=0;i<8;i++)
		{
			filtro_temp[7-i]=filtro_temp[6-i];
		}
		filtro_temp[0]=read_adc();
		for (i=0;i<8;i++)
		{
			promedio_temp=promedio_temp+filtro_temp[i];
		}
		promedio_temp=promedio_temp>>3;
		temperatura=0.4875*promedio_temp;
		lcd_gotoxy(1,2);
		printf(lcd_putc,"%f C",temperatura);
		delay_ms(100);
		promedio_temp=0;	
	}
}
